package com.janyee.powerdroid.http.local

import java.io.IOException

import okhttp3.Interceptor
import okhttp3.Response

/**
 * Created by kmlixh on 2017/2/23.
 * useage:
 * PowerDroid
 */

class LocalResponseInterceptor : Interceptor {
    var localResponseMap: Map<String, LocalResponse>? = null

    override fun intercept(chain: Interceptor.Chain): Response {
        val url = chain.request().url().toString()

        if (localResponseMap != null) {
            val localresponse = localResponseMap!![url]
            if (localresponse != null) {
                return localresponse.toResponse(chain)
            } else {
                return chain.proceed(chain.request())
            }
        } else {
            return chain.proceed(chain.request())
        }

    }
}

